import request from '@/router/axios';

const api = {
    allPlugins: '/flow/workflow/allPlugins',
    start: '/flow/workflow/start',
    upload: '/flow/upload',
}

export const getList = () => new Promise((resolve, reject) => {
    request({
        url: api.allPlugins,
        method: 'get'
    }).then(res => {
        if(res.status === 200) {
            resolve(res.data.result)
        } else {
            resolve([])
        }
    }).catch(err => reject(err))
});

export const uploadFile = (data) => new Promise((resolve, reject) => {
    request({
        url: api.upload,
        headers: {
            'Content-Type': 'multipart/form-data'
        },
        method: 'post',
        data: data
    }).then(res => {
        if(res.status === 200) {
            resolve(res.data.filePath)
        } else {
            resolve('')
        }
    }).catch(err => reject(err))
});

export const runStart = (data) => new Promise((resolve, reject) => {
    request({
        url: api.start,
        method: 'post',
        headers: {
            'Content-Type': 'application/json'
        },
        data: {
            "data": data
        }
    }).then(res => {
        if(res.status === 200) {
            resolve(res.data)
        } else {
            resolve('')
        }
    }).catch(err => reject(err))
});